September Listing 2
         TTL "Listing two: String Examples"
;
;
;
***********************************
*                                 *
*  LISTING 2: An example of       *
*    the various SPEED/ASM string *
*    handling routines.           *
*                                 *
***********************************
;
;
;
;
;
;
;
;
;  GENERAL PURPOSE EQUATES
;
; The following variable are used
; by the SPEED/ASM package and
; shouldn't be used by the SPEED/ASM
; programmer.
;
;
;
;
FORASAV  EPZ 0
FORXSAV  EPZ FORASAV+1
FORYSAV  EPZ FORXSAV+1
FORZPG   EPZ FORYSAV+1
DESTADR  EPZ FORZPG+2
PTRADR   EPZ DESTADR+2
ISIMMED  EPZ PTRADR+2
OP       EPZ ISIMMED+1
MAXLEN   EPZ OP+2
VALUE    EPZ MAXLEN+1
DIGIT    EPZ VALUE+2
LEAD0    EPZ DIGIT+1
JMPADR   EPZ LEAD0+1
COUNT    EPZ JMPADR+2
GOTLN    EPZ COUNT+1
;
;
;
;
;
;
****************
*   CONSTANTS  *
****************
;
;
;
; The following symbols are constants
; for the values "FALSE", "TRUE", and
; Carriage Return (respectively).
;
; These symbol should only appear
; as immediate operands to a 6502
; instruction or in the operand field
; of a pseudo-opcode like BYT.
;
;
;
;
;
FALSE    EQU 0
TRUE     EQU 1
CR       EQU $8D
;
;
;
;
;
;
; "IF" STATEMENT EQUATES
;
; The following symbols should only
; be used in the ADR pseudo-opcode
; following a call to SPEED/ASM
; IFx rountines.
;
;
;
EQ       EQU "="
NE       EQU "#"
GT       EQU ">"
LT       EQU "<"
GE       EQU ">"|"="*256
LE       EQU "<"|"="*256
;
;
;
;
;
;
;
****************************
*  SPEED/ASM ENTRY POINTS  *
****************************
;
;
;
;
; NOTE: THE EQUATE OF PUTC MUST
; BE CHANGED IF YOU RELOCATE
; SPEED/ASM TO SOME LOCATION
; OTHER THAN $7800
;
;
;
PUTC     EQU $7800
GETC     EQU PUTC+3
SAGL     EQU GETC+3          ;FOR USE BY S/A ONLY- SEE DOC.
SAPC     EQU SAGL+3          ; "   "   "  "   "     "   "
HOME     EQU SAPC+3          ;HOME AND CLEAR
READLN   EQU HOME+3
INIT     EQU READLN+3
FOR      EQU INIT+3
FOR0     EQU FOR+3
NEXT     EQU FOR0+3
IFI      EQU NEXT+3
IFI0     EQU IFI+3
IFS      EQU IFI0+3
IFS0     EQU IFS+3
MOVE     EQU IFS0+3
LOAD     EQU MOVE+3
MOVS     EQU LOAD+3
LDSTR    EQU MOVS+3
PRINT    EQU LDSTR+3
PRTSTR   EQU PRINT+3
PRTINT   EQU PRTSTR+3
RDSTR    EQU PRTINT+3
RDINT    EQU RDSTR+3
ONXGOTO  EQU RDINT+3
CASE     EQU ONXGOTO+3
CASEI    EQU CASE+3
INSET    EQU CASEI+3
NOTINSET EQU INSET+3
ABS      EQU NOTINSET+3
NEG      EQU ABS+3
MUL      EQU NEG+3
DIV      EQU MUL+3
MOD      EQU DIV+3
RND      EQU MOD+3
SUBSTR   EQU RND+3
INDEX    EQU SUBSTR+3
LENGTH   EQU INDEX+3
CONCAT   EQU LENGTH+3
;
;
;
;
****************************
;
;
; Begin of program 1.2
;
EXIT     EQU $FF69
;
;
START    JSR INIT            ; Always do this first!
;
;
         JSR HOME
         JSR PRINT
         BYT CR,CR,"SPEED/ASM String Routine Examples",CR,CR,0
;
;
**********************************
*
* The following call to PRESTO
* outputs a string that was pre~
* initialized by LISA.
*
**********************************
;
;
;
         JSR PRTSTR
         ADR STRVAR1
         LDA #CR
         JSR PUTC
;
;
**********************************
*
* The following section of code
* reads a new line of text from
* the keyboard and stuffs it into
* the STOVAR2 variable. If the
* string was too long, the V flag
* is returned set and the user is
* prompted to re-enter the data.
*
**********************************
;
;
ENTERSTR JSR READLN          ;Force a new line from the kbd
         JSR RDSTR
         ADR STRVAR2
         BVC GOODSTR         ;If no error.
;
         JSR PRINT
         BYT CR,"Error: String too long",CR
         BYT "Reenter: ",0
         JMP ENTERSTR
;
;
; Print the string the user just entered.
;
GOODSTR  JSR PRTSTR
         ADR STRVAR2
;
;
**********************************
*
* The following section of code
* loads STRVAR3 with a string
* constant ("This is a string")
* and then copies the STRVAR3
* variable into STOVAR4. After
* all the loading and copying is
* performed/ the contents of the
* strings are displayed.
*
**********************************
;
;
;
; First demonstrate that the strings
; contain nothing.
;
         JSR PRINT
         BYT CR,"STRVAR3 contains """,0
         JSR PRTSTR
         ADR STRVAR3
         JSR PRINT
         BYT """",CR,"STRVAR4 contains """,0
         JSR PRTSTR
         ADR STRVAR4
;
; Now initialize them with LDSTR and MDVS
;
;
         JSR PRINT
         BYT CR,"Using LDSTR to initialize STRVAR3",CR,0
         JSR LDSTR
         ADR STRVAR3
         BYT "This is a string",0
;
;
; Print STRVAR3 and STRVAR4 to show
; that they are indeed different.
;
         JSR PRINT
         BYT CR,"STRVAR3 contains """,0
         JSR PRTSTR
         ADR STRVAR3
         JSR PRINT
         BYT """",CR,"STRVAR4 contains """,0
         JSR PRTSTR
         ADR STRVAR4
;
;
; Now copy STRVAR3 into STRVAR4 and
; print the two strings to shew
; that they are now the same.
;
;
         JSR PRINT
         BYT CR,CR,"Using MOVS to copy STRVAR3 into STRVAR4",CR,0
         JSR MOVS
         ADR STRVAR3,STRVAR4
;
;
         JSR PRINT
         BYT CR,"STRVAR3 contains """,0
         JSR PRTSTR
         ADR STRVAR3
         JSR PRINT
         BYT """",CR,"STRVAR4 contains """,0
         JSR PRTSTR
         ADR STRVAR4
;
;
;
**********************************
*
* The following section of code
* demonstrates the IFSO routine.
* It compares the contents of
* STRVAR3 to the literal "XXXXX"
*
**********************************
;
;
         JSR PRINT
         BYT """",CR,CR,"STRVAR3 is ",0
         JSR IFS0
         ADR STRVAR3,EQ
         BYT "XXXXX",0
         BFL >0
         LDA #"="
         JSR PUTC
         JMP TESTDONE
;
^0       JSR PRINT
         BYT "<>",0
;
TESTDONE JSR PRINT
         BYT " ""XXXXX""",CR,0
;
;
**********************************
*
* This section of code demon-
* strates the IFS routine. It
* loads STRVAR4 with the string
* literal "This is also a string"
* and compares it to STRVAR3.
*
**********************************
;
;
; Load STRVAR4 with "This is also a string"
;
;
         JSR LDSTR
         ADR STRVAR4
         BYT "This is also a string",0
;
; Print the contents of the two
; strings.
;
;
         JSR PRINT
         BYT CR,CR,"STRVAR3 contains: """,0
         JSR PRTSTR
         ADR STRVAR3
         JSR PRINT
         BYT """",CR,"STRVAR4 contains: """,0
         JSR PRTSTR
         ADR STRVAR4
;
         JSR PRINT
         BYT """",CR,0
;
;
; Compare the two strings and see
; if they are equal.
;
;
         JSR IFS
         ADR STRVAR3,EQ,STRVAR4
         BFL >0
         JSR PRINT
         BYT CR,"STRVAR3 = STRVAR4",0
;
; Compare the two strings and see
; if they are not equal.
;
;
^0       JSR IFS
         ADR STRVAR3,NE,STRVAR4
         BFL >1
         JSR PRINT
         BYT CR,"STRVAR3 <> STRVAR4",0
;
;
; Compare the two strings to see
; if STRVAR3 < STRVAR4.
;
^1       JSR IFS
         ADR STRVAR3,LT,STRVAR4
         BFL >2
         JSR PRINT
         BYT CR,"STRVAR3 < STRVAR4",0
;
;
; Check for STRVAR3 <- SIRVAR4
;
^2       JSR IFS
         ADR STRVAR3,LE,STRVAR4
         BFL >3
         JSR PRINT
         BYT CR,"STRVAR3 <= STRVAR4",0
;
;
;
; Check to see if STRVAR3 > STRVAR4.
;
^3       JSR IFS
         ADR STRVAR3,GT,STRVAR4
         BFL >4
         JSR PRINT
         BYT CR,"STRVAR3 > STRVAR4",0
;
;
;
; Is STRVAR3 >= STRVAR4?
;
^4       JSR IFS
         ADR STRVAR3,GE,STRVAR4
         BFL >5
         JSR PRINT
         BYT CR,"STRVAR3 >= STRVAR4",0
;
^5       LDA #CR
         JSR PUTC
;
;
;
;
**********************************
*
* Demonstrate the LENGTH routine
*
**********************************
;
;
         JSR LENGTH
         ADR STRVAR2
         STA LENSTR2
         LDA #0
         STA LENSTR2+1
         JSR PRINT
         BYT "The length of STRVAR2 is ",0
         JSR PRTINT
         ADR LENSTR2
;
;
;
         LDA #CR
         JSR PUTC
;
;
;
;
**********************************
*
* The following code demonstrates
* the use of the SPEED/ASM SUBSIR
* routine.
*
* This code emulates the BASIC
* statements:
*
*
* 10 FOR I = 1 TO 10
* 20 J = 6-I
* 30 PRINT MID$(A$,I,J)
* 40 PRINT MID$(A$,1,I)
* 50 NEXT I
*
         JSR FOR0
         ADR I,1,5
;
         SEC 
         LDA #6
         SBC I
         STA J
         LDA /6
         SBC I+1
         STA J+1
;
         JSR SUBSTR
         ADR STRVAR3,I,J,STRVAR4
         JSR PRTSTR
         ADR STRVAR4
         LDA #CR
         JSR PUTC
;
         JSR SUBSTR
         ADR STRVAR3,ONE,I,STRVAR4
         JSR PRTSTR
         ADR STRVAR4
;
         LDA #CR
         JSR PUTC
         JSR NEXT
;
;
;
*********************************
*
* Test the INDEX routine: This
* code loads STRVAR4 with the
* string "string" and searches for
* "string" within STRVAR3.
*
*********************************
;
;
         JSR LDSTR
         ADR STRVAR4
         BYT "string",0
;
         JSR INDEX
         ADR STRVAR4,STRVAR3
;
         STA STRINDX         ; Store L.O. index into STRINDX
         LDA #0              ; Set H.O. byte of index to zero
         STA STRINDX+1
;
; Print the results:
;
         JSR PRINT
         BYT CR,CR,"""string"" was found at position: ",0
         JSR PRTINT
         ADR STRINDX
         LDA #CR
         JSR PUTC
;
;
**********************************
*
* Demonstrate the GCNCAT routine,
*
* This code concatenates STRVAR4
* (which contains "string") to
* STRVAR3 and prints the result.
*
**********************************
;
;
         JSR CONCAT
         ADR STRVAR3,STRVAR4,STRVAR5
;
         JSR PRINT
         BYT CR,"CONCAT(STRVAR3,STRVAR4)= """,0
         JSR PRTSTR
         ADR STRVAR5
;
         JSR PRINT
         BYT """",CR,0
;
;
;
         JMP EXIT
;
ONE      ADR 1
;
STRVAR1  STR "This string was pre-initialized"
         BYT 0
;
STRVAR2  ADR 128
         DFS 128
;
;
STRVAR3  ADR 30
         DFS 30
;
STRVAR4  ADR 30
         DFS 30
;
STRVAR5  ADR 60
         DFS 60
;
I        ADR 0
J        ADR 0
LENSTR2  ADR 0
STRINDX  ADR 0
;
;
;
         END